/**
 * Created by iallai on 2/1/2018.
 */

import axios from 'axios'
import {CONFIG} from '@/config/env'

let API=CONFIG.PROJECT.API;


const query = (query={}) => new Promise((resolve, reject) => {

  query.is_follow_up=1;
   axios.get(`${API.URL}/admin_threads`,{
     params:query
   }).then(function(res){
       if(API.isOK(res.data)){
         resolve(res.data);
       }
     })
     .catch(function(err){
       reject("网络错误");
   });



});
const get = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/custom`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
  });



});
const getQuery = (data) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/admin_threads/${data.id}`,{
    params:data
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }
    })
    .catch(function(err){
      reject("网络错误");
    });



});

const update = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        if(res.data.bank_card_photo){
          res.data.bank_card_photo=API.BASE+res.data.bank_card_photo;
        }
        if(res.data.id_card_photo){
          res.data.id_card_photo=API.BASE+res.data.id_card_photo;
        }
        if(res.data.driver_license_photo){
          res.data.driver_license_photo=API.BASE+res.data.driver_license_photo;
        }

        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });



});
const add = (query={}) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });



});
const close = (query={}) => new Promise((resolve, reject) => {


  axios({
    method: 'post',
    url: `${API.URL}/admin_threads/close`,
    params:query,

  }).then(function(res){
    if(API.isOK(res.data)){
      resolve(res.data);
    }else{
      reject(res.data.message);
    }
  }).catch(function(err){
    reject("网络错误");
  });


});
const assign = (query={}) => new Promise((resolve, reject) => {

  axios({
    method: 'post',
    url: `${API.URL}/admin_threads/assign`,
    params:query,

  }).then(function(res){
    if(API.isOK(res.data)){
      resolve(res.data);
    }else{
      reject(res.data.message);
    }
  }).catch(function(err){
    reject("网络错误");
  });


});
/**
 *
 * @param {Object} query
 * @returns {Promise<any>}
 */

const credit = (query={} ,other) => new Promise((resolve, reject) => {


  axios.get(`${API.URL}/load_register`,{
    params:query
  }).then(function(res){
      if(API.isOK(res.data)){
        resolve(res.data);
      }else {
        reject("获取认证信息错误");

      }
    })
    .catch(function(err){
      reject("获取认证信息错误");
    });



});


export {get,getQuery,query,credit,assign,update,add,close}

